"""
生成斐波拉切数列的生成器
"""


def fib(num):
    a, b = 0, 1
    for _ in range(num):
        a, b = b, a + b
        yield a


gen = fib(100)
print(type(gen), gen)
# 通过生成器获取数据方法一：使用next函数
print(next(gen))
print(next(gen))
print(next(gen))
print(next(gen))
print(next(gen))
print('-' * 20)
# 通过生成器获取数据方法二：使用for-in循环
for value in gen:
    print(value)
